<?php

class CompanyController extends Controller {
    
    public function actionIndex() {
        $this->render("index");
    }
    
    //Config Table Company
    function actionCompanyInfo() {
        $model = new Company();
        $this->render("CompanyInfo", array(
            "model" => $model
        ));
    }
    function actionCompanyInfoForm($id=NULL) {
        $model = new Company();
        
        // Save
        if (!empty($_POST["Company"])) {
            if (!empty($_POST["Company"]["id"])) {
                $id = $_POST["Company"]["id"];
                $model = Company::model()->findByPk($id);
            }
            $model->_attributes = $_POST["Company"];
            
            if ($model->save()) {
                $this->redirect(array("Company/CompanyInfo"));
            }
        }
        
        // Render
        if (!empty($id)) {
            $model = Company::model()->findByPk($id);
        }
        
        $this->render("CompanyInfoForm", array(
            "model" => $model
        ));
    }
    
    function actionCompanyInfoDelete($id) {
        Company::model()->deleteByPk($id);
        $this->redirect("index.php?r=Company/CompanyInfo");
    }
    //End Config Table Company
    
    //Config Table mt_Company_promotion
    function actionCompanyPromotion() {
        $model = new CompanyPromotion();
        $this->render("CompanyPromotion", array(
            "model" => $model
        ));
    }
    function actionCompanyPromotionForm($id=NULL) {
        $model = new CompanyPromotion();
        
        // Save
        if (!empty($_POST["CompanyPromotion"])) {
            if (!empty($_POST["CompanyPromotion"]["id"])) {
                $id = $_POST["CompanyPromotion"]["id"];
                $model = CompanyPromotion::model()->findByPk($id);
            }
            $model->_attributes = $_POST["CompanyPromotion"];
            
            if ($model->save()) {
                $this->redirect(array("Company/CompanyPromotion"));
            }
        }
        
        // Render
        if (!empty($id)) {
            $model = CompanyPromotion::model()->findByPk($id);
        }
        
        $this->render("CompanyPromotionForm", array(
            "model" => $model
        ));
    }
    
    function actionCompanyPromotionDelete($id) {
        CompanyPromotion::model()->deleteByPk($id);
        $this->redirect("index.php?r=Company/CompanyPromotion");
    }
    //End Config Table mt_company_promotion
    
    //Config Table mt_company_news
    function actionCompanyNews() {
        $model = new CompanyNews();
        $this->render("CompanyNews", array(
            "model" => $model
        ));
    }
    function actionCompanyNewsForm($id=NULL) {
        $model = new CompanyNews();
        
        // Save
        if (!empty($_POST["CompanyNews"])) {
            if (!empty($_POST["CompanyNews"]["id"])) {
                $id = $_POST["CompanyNews"]["id"];
                $model = CompanyNews::model()->findByPk($id);
            }
            $model->_attributes = $_POST["CompanyNews"];
            
            if ($model->save()) {
                $this->redirect(array("Company/CompanyNews"));
            }
        }
        
        // Render
        if (!empty($id)) {
            $model = CompanyNews::model()->findByPk($id);
        }
        
        $this->render("CompanyNewsForm", array(
            "model" => $model
        ));
    }
    
    function actionCompanyNewsDelete($id) {
        CompanyNews::model()->deleteByPk($id);
        $this->redirect("index.php?r=Company/CompanyNews");
    }
}

?>
